/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actor.weapons;

import Actor.Actor;
import Actor.Projectile;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import javax.vecmath.Point2d;

/**
 *
 * @author Eric-Standard
 */
public class Explosion extends Projectile {

    //Current drawn radius
    private double radius;
    private double radiusDelta = 400;
    private double maxRadius = 100;

    public Explosion() {
        super();
        this.fuseTime = 1;
        this.damage = 100;
    }

    public Explosion(Point2d point) {
        super(point);
        this.fuseTime = 1;
        this.damage = 100;
    }

    public void setMaxRadius(double max) {
        maxRadius = max;
    }

    @Override
    public void act(long dt) {
        //Collision is instantaneous
        if (this.fuseTime <= 0) {
            this.collisionDetection = false;
        }
        super.act(dt);
        if (radius >= maxRadius) {
            this.isActive = false;
        } else {
            radius += radiusDelta * dt / 1000f;
            radius = Math.min(radius, maxRadius);
        }
    }

    @Override
    public void draw(Graphics g) {
        g.setColor(Color.RED);
        g.fillOval((int) (pos.x - radius), (int) (pos.y - radius), (int) (2 * radius), (int) (2 * radius));
    }

    @Override
    public void collide(Actor a) {
    }

    public double getDamage(Actor a) {
        return damage * Math.abs(maxRadius - a.getPos().distance(pos)) / maxRadius;
    }
    
    public double getRadius() {
        return maxRadius;
    }

    @Override
    public Rectangle2D getBoundingRectangle() {
        return new Rectangle2D.Double();
    }

    @Override
    public Shape getShape() {
        return new Ellipse2D.Double(pos.x - maxRadius, pos.y - maxRadius, 2 * maxRadius, 2 * maxRadius);
    }
}
